﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using IToursDataService;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;

namespace ToursDataService
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“TravelOrderCtrl”。
    public class TravelOrderCtrl : ITravelOrderCtrl
    {
        /// <summary>
        /// 删除指定计划号的地接社预定信息
        /// </summary>
        /// <param name="tourGroupScheduleID"></param>
        /// <returns></returns>
        public int DeleteTravelOrder(int tourGroupScheduleID)
        {
            Database db = DatabaseFactory.CreateDatabase();

            string sql = string.Format("select expenseid from fee_TravelOrder where TourGroupScheduleID={0}", tourGroupScheduleID);
            DbCommand dbCmd = db.GetSqlStringCommand(sql);

            object expenseObj = db.ExecuteScalar(dbCmd);

            if (expenseObj == null)
                return 0;

            sql = string.Format(@"DELETE FROM fee_TravelOrder WHERE TourGroupScheduleID={0};
                                         DELETE FROM fee_expense WHERE  expenseid={1};", //同时删除费用和地接社相关内容
            tourGroupScheduleID,
            expenseObj.ToString());
            return db.ExecuteNonQuery(CommandType.Text, sql);
        }
    }
}
